package com.tuo51.evaluate.vo.evaluate;

import com.tuo51.evaluate.domain.childrens.Children;
import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Record;
import com.tuo51.evaluate.vo.IDCountDateVO;
import com.tuo51.foudation.utils.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/12/21
 * *******************************
 */
@Data
public class EvaluateChildrenVO {
    private String childrenId;
    private String name;
    private String imgUrl;
    private Integer gender;
    private Integer month;

    private String weight;
    private String height;

    private Integer evaluateTimes=0;
    private Long intervalDay=0L;

    private Date lastEvaluateDate;
    private Date nextEvaluateDate;

    public static EvaluateChildrenVO of(Children children){
        EvaluateChildrenVO vo = new EvaluateChildrenVO();
        vo.setChildrenId(children.getId());
        vo.setName(children.getName());
        vo.setImgUrl(children.getImgUrl());
        vo.setGender(children.getGender());

        vo.setHeight(children.getHeight());
        vo.setWeight(children.getWeight());

        vo.setMonth(DateUtil.betweenMonths(new Date(), children.getBirthday()));

        vo.setLastEvaluateDate(children.getLastEvaluateDate());
        vo.setNextEvaluateDate(children.getNextEvaluateDate());

        return vo;
    }

    public static EvaluateChildrenVO of(Children children, IDCountDateVO countDateVO) {

        EvaluateChildrenVO vo = EvaluateChildrenVO.of(children);

        if (countDateVO != null && countDateVO.getCount().intValue() > 0){
            vo.setEvaluateTimes(countDateVO.getCount().intValue());
            vo.setIntervalDay(DateUtil.betweenDays(countDateVO.getDate(), new Date()));
        }

        return vo;
    }

    public static EvaluateChildrenVO ofV2(Children children, List<EvaluateV2Record> recordList) {

        EvaluateChildrenVO vo = EvaluateChildrenVO.of(children);

        if (Objects.nonNull(recordList) && recordList.size()!=0){
            vo.setEvaluateTimes(recordList.size());
            vo.setIntervalDay(DateUtil.betweenDays(recordList.get(0).getCreated(), new Date()));
        }
        return vo;
    }
}
